<template>
  <div>
    <el-main>
      <el-carousel trigger="manual" height="500px" arrow="always" :interval="2000">
        <el-carousel-item v-for="(flower, index) in flowers" :key="index">
          <div class="carousel-item" @click="handleClick(flower)">
            <img :src="flower.image" alt="Flower" style="width: 100%; height: 500px; object-fit: cover;">
            <div class="flower-name">{{ flower.name }}</div>
          </div>
        </el-carousel-item>
      </el-carousel>
    </el-main>
  </div>
</template>

<script>
export default {
  name: 'CustomSwiper',
  data() {
    return {
      flowers: [
        {name: '中秋爱情鲜花', image: 'https://img02.hua.com/zhuanti/zhongqiu/2024/pc_zhongqiu_banner.jpg'},
        {name: '品牌鲜花', image: 'https://img02.hua.com/slider/23_brand_banner_pc.jpg'},
        {name: '生日鲜花', image: 'https://img02.hua.com/slider/23_birthday_pc.jpg'},
        {name: '爱情鲜花', image: 'https://img02.hua.com/zhuanti/birthday/pc/banner_lover.png'},
      ]
    };
  },
  methods: {
    handleClick(flower) {
      console.log('Clicked on:', flower.name);
      // 根据点击的鲜花名称跳转到对应的页面
      switch (flower.name) {
        case '中秋爱情鲜花':
          this.$router.push('/mid-autumn-love-flowers');
          break;
        case '品牌鲜花':
          this.$router.push('/brand-flowers');
          break;
        case '生日鲜花':
          this.$router.push('/birthday-flowers');
          break;
        case '爱情鲜花':
          this.$router.push('/love-flowers');
          break;
        default:
          console.log('No route found for:', flower.name);
      }
    }
  }
};
</script>

<style scoped>
.carousel-item {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 500px;
}

.flower-name {
  position: absolute;
  bottom: 20px;
  left: 0;
  right: 0;
  margin: auto;
  font-size: 24px;
  color: #c011dc;
  text-align: center;
  background-color: rgba(255, 192, 203, 0.5);
  padding: 10px;
  width: fit-content;
  border-radius: 15px;
  cursor: pointer;
}

img {
  width: 100%;
  height: 500px;
  object-fit: cover;
}
</style>